package com.ithong.mp;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ithong.mp.enums.SexEnum;
import com.ithong.mp.pojo.User;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;

@SpringBootTest
public class testARBoot {

    @Test
    public void testSelectById(){
        User user = new User();
        user.setId(2L);
        User user1 = user.selectById();
        System.out.println(user1);
    }

    @Test public void testAR() {
        User user = new User();
        user.setName("貂蝉");
        user.setAge(30);
        user.setPassword("555555");
        user.setUserName("liubei");
        user.setMail("liubei@itcast.cn");
        user.setVersion(1);
        user.setSex(SexEnum.WOMAN);
        boolean insert = user.insert();
        System.out.println(insert);
    }

    @Test public void testAR1() {
        User user = new User();
        user.setId(8L);
        user.setAge(30);
        boolean update = user.updateById();
        System.out.println(update);
    }

    @Test public void testAR2() {
        User user = new User();
        QueryWrapper<User> userQueryWrapper = new QueryWrapper<>();
        userQueryWrapper.le("age","20");
        List<User> users = user.selectList(userQueryWrapper);
        for (User user1 : users) {
            System.out.println(user1);
        }
    }

    @Test public void testUpdate(){
        User user = new User();
        user.setAge(20);
        boolean result = user.update(null);
        System.out.println("result = " + result);
    }

    @Test
    public void testUpdate2(){
        User user = new User();
        user.setAge(30);    //更新的数据
        user.setId(2L);
        User user1 = user.selectById();
//        user.setVersion(1); //当前的版本信息
        user.setVersion(user1.getVersion()); //当前的版本信息
        //获取到version为1
        boolean result = user.updateById();
        System.out.println("result = " + result);
    }

}
